function CC() {
	/*
	* ONLY ABOUT THE USER CONNECTED
	* not a list of users or something similar. For this, refer to UserManager
	*/

	// singleton
	if (CC.prototype._singletonInstance) {
		return CC.prototype._singletonInstance;
	}
	CC.prototype._singletonInstance = this;

	// set the connexion mode. Facebook or Thank Auth
	var cMode = null;
	// store the user object created if connected
	var user = null;

	/*
	 * Test if the user is connecter either with Facebook or my login system
	 */
	this.testLogin = function() {
		// check if the user is logged with Thank Auth
		if (this.thankAuth()) {
			console.log('logged with Thank Auth');
		}
		// inialize Facebook API and check if the user is logged with Facebook
		else if (this.facebook()) {
			console.log('logged with Facebook');
			// get basic data
			this.facebook.testAPI();
		} else {
			$('.disconnected').show();
			$('.connected').hide();
			console.log('not logged');
		}
	};

	/*
	 * PRIVATE
	 * initialize the Facebook API and get basic data
	 */
	this.facebook = function() {
		// Load the SDK Asynchronously
		( function(d) {
				var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
				if (d.getElementById(id)) {
					return;
				}
				js = d.createElement('script');
				js.id = id;
				js.async = true;
				js.src = "//connect.facebook.net/en_US/all.js";
				ref.parentNode.insertBefore(js, ref);
			}(document));

		// inialize Facebook API
		window.fbAsyncInit = function() {
			FB.init({
				appId : '395207437230562', // App ID
				channelUrl : BASEPATH + 'assets/channel.html', // Channel File
				status : true, // check login status
				cookie : true, // enable cookies to allow the server to access the session
				xfbml : true // parse XFBML
			});

			// Additional init code here

			FB.getLoginStatus(function(response) {
				if (response.status === 'connected') {
					// connected
					onConnected('fb');
				} else if (response.status === 'not_authorized') {
					// not_authorized
					onNotAuthorized();
					return true;
				} else {
					// not_logged_in
					onNotAuthorized();
					return false;
				}
			});
		};

		// ask to login
		this.login = function() {
			FB.login(function(response) {
				if (response.authResponse) {
					// connected
					onConnected('fb');
					// update user info
					testAPI();
				} else {
					// cancelled
				}
			});
		};

		// test API function
		this.testAPI = function() {
			console.log('Welcome!  Fetching your information.... ');
			FB.api('/me', function(response) {
				console.log('Good to see you, ' + response.name + '.');
				// get user info
				uid = response.id;
			});
		}
	};

	this.thankAuth = function() {
		// check if the user is logged
		$.ajax({
			type : 'GET',
			url : '/' + BASEPATH + 'auth/is_logged_in',
			timeout : 3000,
			success : function(data) {
				if (data === 'true') {
					onConnected('ta');
				} else {
					onNotAuthorized();
				}
			},
			error : function() {
				onNotAuthorized();
			}
		});

		/*
		 * Logout from Thank Auth
		 */
		this.logout = function() {
			console.log('logout...');
			// ask to logout
			$.ajax({
				type : 'GET',
				url : '/' + BASEPATH + 'auth/logout',
				timeout : 3000,
				success : function(data) {
					onDisconnected();
				},
				error : function() {
					onNotAuthorized();
				}
			});
		}
	}
	// ask to logout
	this.logout = function() {
		switch(mode) {
			case 'fb' :
				FB.logout(function(response) {
					console.log('User is now logged out');
					onDisconnected();
				});
				break;
			case 'ta' :
				thankAuth.logout()
				console.log('User is now logged out');
				onDisconnected();
				;
				break;
		}
	};

	this.get_uid = function() {
		return user.getUid();
	};

	/*
	 * Get the data
	 *
	 */
	function create_user() {
		switch(cMode) {
			case 'fb':
				FB.api('/me', function(response) {
					// get user info
					var data = [];
					data['id'] = response.id;
					data['username'] = '';
					data['imgURL'] = 'fb';

					console.log('fb id' + response.id);

					// create the user
					user = new U(data);

					console.log('logged user:' + user.getUid());
				});
				break;
			case 'ta':
				// get the id from php
				$.ajax({
					type : 'GET',
					url : '/' + BASEPATH + 'auth/get_uid/',
					timeout : 3000,
					success : function(data) {
						$.ajax({
							type : 'GET',
							url : '/' + BASEPATH + 'U/get/mini/' + data,
							timeout : 3000,
							success : function(data) {
								user = new U(data[0]);
								if ( typeof (MM) != undefined) {
									locate();
								}

								//UMC.display_miniBox(user, '#miniBox');
								console.log('logged user:' + user.getUid());
							},
							error : function() {
								onNotAuthorized();
							}
						});

					},
					error : function() {
						onNotAuthorized();
					}
				});
				break;
		}
	}

	function locate() {
		if ( typeof (MM) == 'undefined') {
			console.log('screwed up');
		}
		if ( typeof (MM) != 'undefined') {
			switch(cMode) {
				case null :
					// locate map
					MM.locate('here');
					break;
				case 'fb' :
					// locate map
					MM.locate('here');
					break;
				case 'ta' :
					// locate map
					if (user.lat != '0' && user.lng != '0') {
						// distance is taken from the user coordinates
						MC.set_distanceFrom('user');
						// move to the registred location
						MM.locate('coord', user.lat, user.lng);
					} else {
						// distance is taken from the map center
						MM.set_distanceFrom('here');
						// locate map
						MM.locate('here');
					}
					break;
			}
		}
	}

	function onConnected(mode) {
		switch(mode) {
			// logged in with facebook
			case 'fb':
				console.log('connected with Facebook');

				// set the mode of connection
				cMode = 'fb';
				break;

			// logged in with ThankAuth
			case 'ta':
				console.log('connected with Thank Auth');

				// set the mode of connection
				cMode = 'ta';
				break;
		}

		// create connected user and then locate him
		create_user();

		// switch login/logout menu
		$('.connected').show();
		$('.disconnected ').hide();
	}

	function onNotAuthorized() {
		mode = null;

		// locate map
		if ( typeof (MM) != undefined) {
			locate();
		}

		// switch login/logout menu
		$('#user').hide();
		$('#connection').show();
	}

	function onDisconnected() {
		mode = null;

		// locate map
		if ( typeof (MM) != undefined) {
			MM.locate('here');
		}

		// switch login/logout menu
		$('.connected').hide();
		$('.disconnected').show();
	}


	console.log('CC loaded');
}